package xin.yangshuai.leetcode01;

import java.io.*;

/**
 * Hello
 *
 * @author shuai
 * @date 2021/6/25
 */
public class Hello {
    public static void main(String[] args) throws IOException {
        int[] array = {25, 34, 12, 76, 101, 97, 28};
        int[] s2l = s2l(array);

        for (int i : s2l) {
            System.out.print(i + "、");
        }
        System.out.println();
        int[] l2s = l2s(array);
        for (int i : l2s) {
            System.out.print(i + "、");
        }


        String str = getString("HelloWorld");
        System.out.println(str);


        copyFile("E:\\123.jpg", "E:\\456.jpg");

    }


    public static int calculate(int x) {
        int y;
        if (x > 0) {
            y = x + 3;
        } else if (x == 0) {
            y = x;
        } else {
            y = x * x - 1;
        }
        return y;
    }

    // 小到大
    public static int[] s2l(int[] array) {
        for (int i = 0; i < array.length; i++) {
            for (int j = i + 1; j < array.length; j++) {
                if (array[i] > array[j]) {
                    int temp = array[i];
                    array[i] = array[j];
                    array[j] = temp;
                }
            }
        }
        return array;
    }

    // 大到小
    public static int[] l2s(int[] array) {
        for (int i = 0; i < array.length; i++) {
            for (int j = i + 1; j < array.length; j++) {
                if (array[i] < array[j]) {
                    int temp = array[i];
                    array[i] = array[j];
                    array[j] = temp;
                }
            }
        }
        return array;
    }


    public static String getString(String s) {
        char[] chars = s.toCharArray();
        StringBuilder stringBuilder = new StringBuilder();
        for (int i = chars.length - 1; i >= 0; i--) {
            char aChar = chars[i];
            String value = String.valueOf(aChar);
            if ('a' <= aChar && aChar <= 'z') {
                value = value.toUpperCase();
            } else if ('A' <= aChar && aChar <= 'Z') {
                value = value.toLowerCase();
            }
            stringBuilder.append(value);
        }
        return stringBuilder.toString();
    }


    private static void copyFile(String source, String target)
            throws IOException {
        InputStream input = null;
        OutputStream output = null;
        try {
            input = new FileInputStream(source);
            output = new FileOutputStream(target);
            byte[] buf = new byte[1024];
            int bytesRead;
            while ((bytesRead = input.read(buf)) != -1) {
                output.write(buf, 0, bytesRead);
            }
        } finally {
            input.close();
            output.close();
        }
    }

}
